package com.jwgf.smarowindingmachine_unity.ui;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.jwgf.common.ViewCache;
import com.jwgf.smarowindingmachine_unity.R;

public class EquipmentMaintenanceMenuFragment extends MenuFragment implements
        OnClickListener {
    public static final String fragmentTag = "EquipmentMaintenanceMenuFragment";
    private Button functionBtn;
    private Button spindleUpgradeBtn;
    private Button passwordBtn;
    private Button upgradeBtn;
    private Button deviceBtn;
    private Button networkBtn;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = ViewCache.getInstance().getView(R.layout.fragment_equipment_maintenance_menu);
//        View v = inflater.inflate(R.layout.fragment_equipment_maintenance_menu,
//                container, false);
        functionBtn = (Button) v.findViewById(R.id.btn_function);
        spindleUpgradeBtn = v.findViewById(R.id.btn_spindle_upgrade);
        passwordBtn = (Button) v.findViewById(R.id.btn_password);
        upgradeBtn = (Button) v.findViewById(R.id.btn_upgrade);
        deviceBtn = (Button) v.findViewById(R.id.btn_device);
        networkBtn = (Button) v.findViewById(R.id.btn_network);

        functionBtn.setSelected(true);

        functionBtn.setOnClickListener(this);
        spindleUpgradeBtn.setOnClickListener(this);
        passwordBtn.setOnClickListener(this);
        upgradeBtn.setOnClickListener(this);
        deviceBtn.setOnClickListener(this);
        networkBtn.setOnClickListener(this);
        return v;
    }

    @Override
    protected void switchSelection(int id) {
        if (id == R.id.btn_function) {
            functionBtn.setSelected(true);
            spindleUpgradeBtn.setSelected(false);
            passwordBtn.setSelected(false);
            upgradeBtn.setSelected(false);
            deviceBtn.setSelected(false);
            networkBtn.setSelected(false);
        } else if (id == R.id.btn_spindle_upgrade) {
            functionBtn.setSelected(false);
            spindleUpgradeBtn.setSelected(true);
            passwordBtn.setSelected(false);
            upgradeBtn.setSelected(false);
            deviceBtn.setSelected(false);
            networkBtn.setSelected(false);
        } else if (id == R.id.btn_password) {
            functionBtn.setSelected(false);
            spindleUpgradeBtn.setSelected(false);
            passwordBtn.setSelected(true);
            upgradeBtn.setSelected(false);
            deviceBtn.setSelected(false);
            networkBtn.setSelected(false);
        } else if (id == R.id.btn_upgrade) {
            functionBtn.setSelected(false);
            spindleUpgradeBtn.setSelected(false);
            passwordBtn.setSelected(false);
            upgradeBtn.setSelected(true);
            deviceBtn.setSelected(false);
            networkBtn.setSelected(false);
        } else if (id == R.id.btn_network) {
            functionBtn.setSelected(false);
            spindleUpgradeBtn.setSelected(false);
            passwordBtn.setSelected(false);
            upgradeBtn.setSelected(false);
            deviceBtn.setSelected(false);
            networkBtn.setSelected(true);
        } else if (id == R.id.btn_device) {
            functionBtn.setSelected(false);
            spindleUpgradeBtn.setSelected(false);
            passwordBtn.setSelected(false);
            upgradeBtn.setSelected(false);
            deviceBtn.setSelected(true);
            networkBtn.setSelected(false);
        }
    }

    @Override
    public void onClick(View v) {
        SwitchPageManager.getInstance().switchSecondMenu(getFragmentManager(), v.getId());
    }
}